<!DOCTYPE html>
<!--suppress ALL-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台管理界面-LeDao的博客</title>
    <link rel="short icon" href="/static/images/favicon.ico">
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/metro-blue/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="/static/jquery-easyui-1.7.0/themes/icon.css"/>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/static/jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        if (window.name != "refresh") {
            location.reload();
            window.name = "refresh";
        } else {
            window.name = "";
        }

        $(document).ready(function () {
            // 监听右键事件，创建右键菜单
            $('#tabs').tabs({
                onContextMenu: function (e, title, index) {
                    e.preventDefault();
                    if (index > 0) {
                        $('#menu').menu('show', {
                            left: e.pageX,
                            top: e.pageY
                        }).data("tabTitle", title);
                    }
                }
            });

            // 右键菜单click
            $("#menu").menu({
                onClick: function (item) {
                    closeTab(this, item.name);
                }
            });

            function closeTab(menu, type) {
                var allTabs = $("#tabs").tabs('tabs');
                var allTabtitle = [];
                $.each(allTabs, function (i, n) {
                    var opt = $(n).panel('options');
                    if (opt.closable)
                        allTabtitle.push(opt.title);
                });
                var curTabTitle = $(menu).data("tabTitle");
                var curTabIndex = $("#tabs").tabs("getTabIndex", $("#tabs").tabs("getTab", curTabTitle));
                switch (type) {
                    case "1": // 刷新当前标签页
                        var currentTab = $('#tabs').tabs('getSelected');
                        var url = $(currentTab.panel('options')).attr('href');
                        $('#tabs').tabs('update', {
                            tab: currentTab,
                            options: {
                                href: url
                            }
                        });
                        currentTab.panel('refresh');
                        // var panel = $("#tabs").tabs("getTab", curTabTitle).panel("refresh");
                        break;
                    case "2": // 关闭当前标签页
                        $("#tabs").tabs("close", curTabIndex);
                        return false;
                        break;
                    case "3": // 关闭全部标签页
                        for (var i = 0; i < allTabtitle.length; i++) {
                            $('#tabs').tabs('close', allTabtitle[i]);
                        }
                        break;
                    case "4": // 关闭其他标签页
                        for (var i = 0; i < allTabtitle.length; i++) {
                            if (curTabTitle != allTabtitle[i])
                                $('#tabs').tabs('close', allTabtitle[i]);
                        }
                        $('#tabs').tabs('select', curTabTitle);
                        break;
                    case "5": // 关闭右侧标签页
                        for (var i = curTabIndex; i < allTabtitle.length; i++) {
                            $('#tabs').tabs('close', allTabtitle[i]);
                        }
                        $('#tabs').tabs('select', curTabTitle);
                        break;
                    case "6": // 关闭左侧标签页
                        for (var i = 0; i < curTabIndex - 1; i++) {
                            $('#tabs').tabs('close', allTabtitle[i]);
                        }
                        $('#tabs').tabs('select', curTabTitle);
                        break;

                }

            }
        });

        function changeSkin() {
            $.messager.confirm("系统提示", "您确定要切换前台皮肤吗?", function (r) {
                if (r) {
                    $.post("/changeSkin", {}, function (result) {
                        if (result.success) {
                            $.messager.alert("系统提示", "已经成功切换前台皮肤!!");
                        } else {
                            $.messager.alert("系统提示", "切换失败!!");
                        }
                    })
                }
            });
        }

        function changeSendMail() {
            $.post("/readSendMail", {}, function (result) {
                if (result.success) {
                    if (result.status == "0") {
                        $.messager.confirm("系统提示", "您确定要设置有人评论时邮件提醒吗?", function (r) {
                            if (r) {
                                $.post("/changeSendMail", {}, function (result) {
                                    if (result.success) {
                                        $.messager.alert("系统提示", "邮件提醒设置成功！！");
                                        $("#sendMailStatus").html("已设置");
                                        $("#sendMailStatus").css('color', 'blue');
                                    } else {
                                        $.messager.alert("系统提示", "邮件提醒设置失败！！");
                                    }
                                })
                            }
                        });
                    } else if (result.status == "1") {
                        $.messager.confirm("系统提示", "您确定要取消有人评论时邮件提醒吗?", function (r) {
                            if (r) {
                                $.post("/changeSendMail", {}, function (result) {
                                    if (result.success) {
                                        $.messager.alert("系统提示", "邮件提醒取消成功！！");
                                        $("#sendMailStatus").html("未设置");
                                        $("#sendMailStatus").css('color', 'red');
                                    } else {
                                        $.messager.alert("系统提示", "邮件提醒取消失败！！");
                                    }
                                })
                            }
                        });
                    }
                }
            })
        }

        function backup() {
            $.messager.confirm("系统提示", "您确定要备份数据吗?", function (r) {
                if (r) {
                    $.post("/backup", {}, function (result) {
                        if (result.success) {
                            $.messager.alert("系统提示", "已经成功备份数据!!");
                        } else {
                            $.messager.alert("系统提示", "备份失败!!");
                        }
                    })
                }
            });
        }

        function logout() {
            $.messager.confirm("系统提示", "您确定要退出系统吗?", function (r) {
                if (r) {
                    window.location.href = "/logout";
                }
            });
        }

        function openTab(text, url, iconCls) {
            if ($("#tabs").tabs("exists", text)) {
                $("#tabs").tabs("select", text);
            } else {
                var content = "<iframe frameborder=0 scrolling='auto' style='width:100%;height:99.3%' src='/admin/" + url + "'></iframe>";
                $("#tabs").tabs("add", {
                    title: text,
                    iconCls: iconCls,
                    closable: true,
                    content: content
                });
            }
        }

        function openChangeCodeStyleDialog() {
            $("#dlg").dialog("open").dialog("setTitle", "修改代码风格");
            $.post("/readCodeStyle", {}, function (result) {
                if (result.success) {
                    $("#nowCodeStyle").val(result.codeStyle);
                }
            })
            $("#codeStyle").get(0).focus();
        }

        function openChangeSkinDialog() {
            $("#dlg2").dialog("open").dialog("setTitle", "修改皮肤");
            $("#skin").get(0).focus();
        }

        function modifyCodeStyle() {
            $("#fm").form("submit", {
                onSubmit: function () {
                    let codeStyle = $("#codeStyle").val();
                    if (!$(this).form("validate")) {
                        return false;
                    }
                    return true;
                },
                url: "/changeCodeStyle?codeStyle=" + $("#codeStyle").val(),
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.success) {
                        $.messager.alert("系统提示", "代码风格修改成功");
                        resetValue();
                        $("#dlg").dialog("close");
                    } else {
                        $.messager.alert("系统提示", "代码风格修改失败");
                    }
                }
            });
        }

        function modifySkin() {
            $("#fm2").form("submit", {
                onSubmit: function () {
                    let skin = $("#skin").val();
                    if (!$(this).form("validate")) {
                        return false;
                    }
                    return true;
                },
                url: "/changeSkin?skin=" + $("#skin").val(),
                success: function (result) {
                    var result = eval('(' + result + ')');
                    if (result.success) {
                        $.messager.alert("系统提示", "皮肤修改成功");
                        resetValue();
                        $("#dlg2").dialog("close");
                    } else {
                        $.messager.alert("系统提示", "皮肤修改失败");
                    }
                }
            });
        }

        function closeChangeCodeStyleDialog() {
            resetValue();
            $("#dlg").dialog("close");
        }

        function closeChangeSkinDialog() {
            resetValue2();
            $("#dlg2").dialog("close");
        }

        function resetValue() {
            $("#codeStyle").val("");
        }

        function resetValue2() {
            $("#skin").val("");
        }
    </script>
</head>
<body class="easyui-layout">
<div region="north" style="height: 82px;background-color: #daeef5">
    <table style="padding: 2px" width="100%">
        <tr>
            <td width="50%">
                <img alt="logo" src="/static/images/logo.png" style="height: 65px"/>
            </td>
            <td valign="bottom" align="right" width="50%">
                <span style="font-size: 18px">&nbsp;&nbsp;<strong>当前用户：</strong><span
                        th:text="${session.currentUserNickName}" style="color: blue"></span></span>
                <span style="font-size: 18px">&nbsp;&nbsp;<strong>邮件提醒：</strong><span
                        th:text="${session.sendMailStatus}" id="sendMailStatus"
                        th:style="${session.sendMailStatus == '未设置'?'color:red':'color:blue'}"></span></span>
            </td>
        </tr>
    </table>
</div>

<div region="center">
    <div class="easyui-tabs" fit="true" border="false" id="tabs">
        <div title="首页" data-options="iconCls:'icon-home'">
            <div align="center" style="padding-top: 160px"><span
                    style="font-size: 40px;color: orangered">LeDao博客系统后台首页</span></div>
        </div>
    </div>
</div>

<div region="west" style="width: 200px" title="导航菜单" split="true">
    <div style="padding-top: 10px;padding-left: 10px;">
        <a href="javascript:openTab('写博客','writeBlog.html','icon-writeBlog')" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-writeBlog'" style="width: 150px;">写博客</a>
        <a href="javascript:openTab('博客类别管理','blogTypeManage.html','icon-blogTypeManage')" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-blogTypeManage'" style="width: 150px;">博客类别管理</a>
        <a href="javascript:openTab('博客管理','blogManage.html','icon-blogManage')" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-blogManage'" style="width: 150px;">博客管理</a>
        <a href="javascript:openTab('友情链接管理','linkManage.html','icon-linkManage')" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-linkManage'" style="width: 150px;">友情链接管理</a>
        <a href="javascript:openTab('评论管理','commentManage.html','icon-commentManage')" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-commentManage'" style="width: 150px;">评论管理</a>
        <a href="javascript:openTab('ip封禁管理','ipBanManage.html','icon-ipBanManage')" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-ipBanManage'" style="width: 150px;">ip封禁管理</a>
        <a href="javascript:openTab('查看点赞记录','likeManage.html','icon-likeManage')" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-likeManage'" style="width: 150px;">查看点赞记录</a>
        <a href="javascript:openTab('查看访问记录','interviewRecordManage.html','icon-interviewRecordManage')"
           class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-interviewRecordManage'"
           style="width: 150px;">查看访问记录</a>
        <a href="javascript:openTab('每日访问ip个数','countIpNumByDay.html','icon-countIpNumByDay')"
           class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-countIpNumByDay'"
           style="width: 150px;">每日访问ip个数</a>
        <a href="javascript:openTab('每日访问总数','countInterviewNumByDay.html','icon-countInterviewNumByDay')"
           class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-countInterviewNumByDay'"
           style="width: 150px;">每日访问总数</a>
        <a href="javascript:openChangeSkinDialog()" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-changeSkin'"
           style="width: 150px;float: left">切换前台皮肤</a>
        <a href="javascript:backup()" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-backup'"
           style="width: 150px;float: left">一键备份数据</a>
        <a href="javascript:changeSendMail()" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-sendMail'"
           style="width: 150px;float: left">是否邮件提醒</a>
        <a href="javascript:openChangeCodeStyleDialog()" class="easyui-linkbutton"
           data-options="plain:true,iconCls:'icon-changeCodeStyle'"
           style="width: 150px;float: left">修改代码风格</a>
        <a href="javascript:logout()" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-exit'"
           style="width: 150px;float: left">安全退出</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog" style="width: 400px;height: 180px;padding: 10px 20px" closed="true"
     buttons="#dlg-buttons" data-options="onClose:function(){resetValue()}">
    <form id="fm" method="post">
        <table cellspacing="8px">
            <tr>
                <td>当前风格名称:</td>
                <td>
                    <input type="text" disabled="disabled" id="nowCodeStyle" class="easyui-validatebox"
                           required="true" style="width: 200px">
                </td>
            </tr>
            <tr>
                <td>新代码风格名称:</td>
                <td>
                    <input type="text" id="codeStyle" class="easyui-validatebox"
                           required="true" style="width: 200px">
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:modifyCodeStyle()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closeChangeCodeStyleDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
<div id="dlg2" class="easyui-dialog" style="width: 400px;height: 144px;padding: 10px 20px" closed="true"
     buttons="#dlg-buttons2" data-options="onClose:function(){resetValue2()}">
    <form id="fm2" method="post">
        <table cellspacing="8px">
            <tr>
                <td>皮肤名称:</td>
                <td>
                    <input type="text" id="skin" class="easyui-validatebox"
                           required="true" style="width: 200px">
                </td>
            </tr>
        </table>
    </form>
</div>
<div id="dlg-buttons2">
    <a href="javascript:modifySkin()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
    <a href="javascript:closeChangeSkinDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
<div id="menu" class="easyui-menu">
    <div id="mm-tabrefresh" data-options="name:'1',iconCls:'icon-refresh'"> 刷新当前标签页</div>
    <div class="menu-sep"></div>
    <div id="mm-tabclose" data-options="name:'2',iconCls:'icon-closetab'">关闭当前标签页</div>
    <div id="mm-tabcloseall" data-options="name:'3',iconCls:'icon-closealltab'">关闭全部标签页</div>
    <div id="mm-tabcloseother" data-options="name:'4',iconCls:'icon-closeothertab'">关闭其他标签页</div>
    <div id="mm-tabcloseright" data-options="name:'5',iconCls:'icon-closerighttab'">关闭右侧标签页</div>
    <div id="mm-tabcloseleft" data-options="name:'6',iconCls:'icon-closelefttab'">关闭左侧标签页</div>
</div>
<div region="south" style="height: 30px;padding: 5px" align="center">
    Copyright © www.zoutl.cn
</div>
</body>
</html>
